<?php

include_once 'Expression.php';
include_once 'Statement.php';
include_once 'IterationStatement.php';

/**
 * Represents a for statement
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ForStatementExample.php 
 */

class ForStatement extends IterationStatement
{
    /**
     * The ForStatement constructor
     * 
     * @param Statement $InitStatement The for loop initialization statement
     * @param Expression $TestExpression The expression to test for loop termination
     * @param Statement $IncrementStatement The for loop increment statement
     */
    
    public function __construct(Statement $InitStatement = null,
        Expression $TestExpression = null, Statement $IncrementStatement = null)
    {
        parent::__construct();
        
        is_null($TestExpression) ?
            $this->IncrementStatement = new Statement() :
            $this->set_IncrementStatement($IncrementStatement);
        
        is_null($InitStatement) ?
            $this->InitStatement = new Statement() :
            $this->set_InitStatement($InitStatement);
        
        is_null($TestExpression) ?
            $this->TestExpression = new Expression() :
            $this->set_TestExpression($TestExpression);
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'IncrementStatement')
        {
            $this->set_IncrementStatement($value);
        }
        
        if($name == 'InitStatement')
        {
            $this->set_InitStatement($value);
        }
        
        if($name == 'TestExpression')
        {
            $this->set_TestExpression($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'IncrementStatement')
        {
            return $this->get_IncrementStatement();
        }
        
        if($name == 'InitStatement')
        {
            return $this->get_InitStatement();
        }
        
        if($name == 'TestExpression')
        {
            return $this->get_TestExpression();
        }
    }
    
    /**
     * The $IncrementStatement getter method
     * @return Statement 
     */
    
    public function get_IncrementStatement()
    {
        return $this->IncrementStatement;
    }

    /**
     * The IncrementStatement setter method
     * @param Statement $IncrementStatement 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_IncrementStatement(Statement $IncrementStatement)
    {
        $this->IncrementStatement = $IncrementStatement;
    }

    /**
     * The $InitStatement getter method
     * @return Statement 
     */
    
    public function get_InitStatement()
    {
        return $this->InitStatement;
    }

    /**
     * The $InitStatement setter method
     * @param Statement $InitStatement 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_InitStatement(Statement $InitStatement)
    {
        $this->InitStatement = $InitStatement;
    }

    /**
     * The $TestExpression getter method
     * @return Expression 
     */
    
    public function get_TestExpression()
    {
        return $this->TestExpression;
    }

    /**
     * The $TestExpression setter method
     * @param Expression $TestExpression 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     * @assert (new stdClass()) throws PHPUnit_Framework_Error
     */
    
    public function set_TestExpression(Expression $TestExpression)
    {
        $this->TestExpression = $TestExpression;
    }

    /**
     * The for loop increment statement
     * @var Statement 
     */
    
    private $IncrementStatement;
    
    /**
     * The for loop initialization statement
     * @var Statement 
     */
    
    private $InitStatement;
    
    /**
     * The expression to test for loop termination
     * @var Expression 
     */
    
    private $TestExpression;
}

?>
